package com.gxg.services;

import java.io.UnsupportedEncodingException;
import org.springframework.stereotype.Service;

@Service
public class GetEncodingService
{
  public String getEncoding(String str)
  {
    String encoding = "UTF-8";
    try
    {
      if (str.equals(new String(str.getBytes(), encoding))) {
        return encoding;
      }
    }
    catch (UnsupportedEncodingException e)
    {
      e.printStackTrace();
    }
    encoding = "GBK";
    try
    {
      if (str.equals(new String(str.getBytes(), encoding))) {
        return encoding;
      }
    }
    catch (UnsupportedEncodingException e)
    {
      e.printStackTrace();
    }
    encoding = "ISO-8859-1";
    try
    {
      if (str.equals(new String(str.getBytes(), encoding))) {
        return encoding;
      }
    }
    catch (UnsupportedEncodingException e)
    {
      e.printStackTrace();
    }
    encoding = "GB2312";
    try
    {
      if (str.equals(new String(str.getBytes(), encoding))) {
        return encoding;
      }
    }
    catch (UnsupportedEncodingException e)
    {
      e.printStackTrace();
    }
    return null;
  }
}
